/*
 *  This file is part of Cube.
 *
 *  Cube is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Cube is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Cube.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package cube.charts;

import cube.CubeView;
import javax.swing.JInternalFrame;
import org.apache.log4j.Logger;

/**
 *
 * @author akermanl
 */
public class CubeChart extends Chart 
{
    protected static final Logger log = Logger.getLogger(CubeView.class);
    private Cube cube;
    private boolean animated = false;
    private boolean realTimeEnabled=false;
    ChartManager chartManager;
    private String design;
   
    //public  CubeChart(ChartManager chartManager) {
      //  super();   
    public  CubeChart(ChartManager chartManager, String title, int xPos, int yPos, int width, int height) {
        super(title, xPos, yPos, width, height);  
        this.chartManager=chartManager;
        cube = new Cube(chartManager);
        cube.setSize(355, 355);
        setContentPane(this.cube);
        this.setDesign("grid");
    }
    
    public void rotate(double deltaAngleX,double deltaAngleY,double deltaAngleZ){
        cube.rotate(deltaAngleX, deltaAngleY, deltaAngleZ);     
    }
    
    public void setAngles(double AngleX,double AngleY,double AngleZ){
        cube.setAngles(AngleX, AngleY, AngleZ);     
    }
    
    public boolean realTimeEnabled(){
        return realTimeEnabled;
    }
    
    public void setRealTimeStatus(boolean realTimeStatus){
        realTimeEnabled=realTimeStatus;
        if (realTimeEnabled)
            this.startRealTimeModus();
    }
    
    public void startRealTimeModus(){
            new Thread(){ 
                    @Override public void run() {
                        while(realTimeEnabled()){
                            
                    }
                }
            }.start();
    }
   
    
    
    public void startAnimation(){
        setAnimated(true);
        new Thread() { 
            @Override public void run() { 
                while(isAnimated()){
                    cube.rotate(0.01,0.0075,0.005); 
                    try {
                        Thread.sleep( 50 ); 
                    }
                    catch ( InterruptedException e )  { 
                        log.debug( "Interruption in animation" ); 
                    }
                }
                
            } 
        }.start();
        
    }
    
    public void stopAnimation(){
        setAnimated(false);
    }

    public boolean isAnimated() {
        return animated;
    }

    public void setAnimated(boolean animated) {
        this.animated = animated;
    }

    public String getDesign() {
        return design;
    }

    public void setDesign(String type) {
        this.design = type;
    }
    
    public void resetValues(){
        this.setAngles(0, 0, 0);
    }
    
    


}
